﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LY.Entity;
using LY.Entity.Entities;
using LY.Entity.Jsons;
using LY.Entity.PageSearch;
using LY.Entity.SearchEntity;
using LY.Extension;
using LY.Interface;

namespace QJ.CMS.Areas.Admin.Controllers
{
    public class ScoreMgrController : MyControllerBase
    {
        //
        // GET: /Admin/ScoreMgr/

        private IScoreService _scoreService;

        public ScoreMgrController(IScoreService scoreService)
        {
            _scoreService = scoreService;
        }


        public ActionResult ScoreSettingList()
        {
            return View();
        } 
        [HttpPost]
        public ActionResult ScoreSettingList(ScoreSearch search, FormCollection form)
        {
            PageView view = new PageView(form);
            string colkey = form["colkey"];
            string colsinfo = form["colsinfo"];
            PagedList<U_ScoreSetting> list = _scoreService.QueryScoreSettingList(search, view);
            JsonQTable fdata = JsonQTable.ConvertFromPagedList<U_ScoreSetting>(list, colkey, colsinfo.Split(','));
            return Json(fdata);
        }
        public ActionResult ScoreSettingEdit(int id=0)
        {
            var model = new U_ScoreSetting {extcredits1 = 0};
            if (id != 0)
            {
                model = _scoreService.GetScoreSetting(id);

            } 
            return View(model);
        }

        [HttpPost]
        public JsonResult ScoreSettingEdit(U_ScoreSetting scoreSetting)
        {  
            var rMsg = new JsonSMsg(); 
            try
            { 
                int ret = _scoreService.SaveScoreSetting(scoreSetting);
                if (ret > 0)
                {
                    rMsg.Status = 1;
                    rMsg.Message = "操作成功！";
                }
                else
                {
                    rMsg.Status = -1;
                    rMsg.Message = "意外错误，请稍后重试！";
                }
            }
            catch (Exception ex)
            {
                rMsg.Status = -1;
                rMsg.Message = ex.Message;
            }
            rMsg.Data = Url.Action("ScoreSettingList");
            return Json(rMsg); 
        }
    }
}
